<?php
use services\models\Payment;
use services\models\OrderInfo;


?>

<?php $this->beginBlock('css');?>
  <link rel="stylesheet" type="text/css" href="<?= Yii::getAlias('@static')?>/pc/liketry/css/shop.css">
<?php $this->endBlock();?>

<?= $this->render('@liketry/views/layouts/header_shop.php',['step'=>3])?>
<div class="main">
	<div class="pay-content">
    	<div class="pay-settle">
        	<div class="pay-rtime-wrap"><span>为了保证及时处理您的订单，请于下单<i>12小时</i>内付款，若预期未付款订单将会被取消，需重新下单。</span><span class="icon icon-rtime"><span class="pay-rtime-title">剩余付款时间</span><span class="pay-rtime" id="payRtime"></span></span></div>
            <div class="pay-settle-info">商品数量：<i><?=$order->goodsTotal?></i><br>试豆支付：<strong><?=$order->try_coin?></strong>（已扣除，当取消支付时立即返还）<br>人民币支付：<strong>￥<?=$order->order_amount?></strong></div>
        </div>
        <div class="pay-method">
        	<h2>支付平台</h2>
            <div class="pay-method-list">
            	<label><input type="radio" id="alipay" value="<?=OrderInfo::$PAY_TYPE_ALIPAY?>" name="pay-method"><span class="bank bank-alipay"></span></label>
                <label><input type="radio" id="wxpay"  value="<?=OrderInfo::$PAY_TYPE_WEIXIN?>" name="pay-method"><span class="bank bank-wxpay"></span></label>
                <span class="pay-method-more-open">更多网银支付<span class="icon icon-arrow-down3"></span></span>
            </div>
            <div class="pay-method-more">
            	<h2>网银支付</h2>
                <div class="pay-method-more-list">
                    <label><input type="radio" id="cmb" name="pay-method" value="CMB"><span class="bank bank-cmb"></span></label>
                    <label><input type="radio" id="icbc" name="pay-method" value="ICBCB2C" ><span class="bank bank-icbc"></span></label>
                    <label><input type="radio" id="abc" name="pay-method" value="ABC"><span class="bank bank-abc"></span></label>
                    <label><input type="radio" id="boc" name="pay-method" value="BOCB2C"><span class="bank bank-boc"></span></label>
                    <label><input type="radio" id="bcm" name="pay-method" value="COMM"><span class="bank bank-bcm"></span></label>
                    <label><input type="radio" id="psbc" name="pay-method" value="POSTGC"><span class="bank bank-psbc"></span></label>
                    <label><input type="radio" id="ceb" name="pay-method"  value="CEBBANK"><span class="bank bank-ceb"></span></label>
                    <label><input type="radio" id="pingan" name="pay-method" value="SPABANK"><span class="bank bank-pingan"></span></label>
                    <label><input type="radio" id="spdb" name="pay-method" value="SPDB"><span class="bank bank-spdb"></span></label>
                    <label><input type="radio" id="cmbc" name="pay-method" value="CMBC"><span class="bank bank-cmbc"></span></label>
                    <label><input type="radio" id="cib" name="pay-method" value="CIB"><span class="bank bank-cib"></span></label>
                </div>
            </div>
            <div class="pay-submit"><span class="icon icon-btn3" id="payBtn">立即支付</span><span class="error"></span></div>
        </div>
        <div class="pay-order">
        	<span>订单号：<?=$order->order_sn?></span> <a href="<?=Yii::$app->urlManager->createAbsoluteUrl(['order-details/order-detail', 'order_info_id'=>$order->order_info_id])?>">查看订单详情</a><br>
        	<span>收货信息：<?php
            /** @var \services\models\OrderExpress $addressInfo */
            $addressInfo = $order->orderExpress;
            echo $addressInfo->province, $addressInfo->city, $addressInfo->county, $addressInfo->address;
            ?>
            </span>
			<span>收货人：<?=$addressInfo->consignee?></span> <span>手机号：<?=$addressInfo->mobile_phone?></span>
        </div>
    </div>
</div>

<?php $this->beginBlock('js');?>
<script src="<?= Yii::getAlias('@static')?>/pc/common/js/jquery-1.12.3.min.js"></script> 
<script src="<?= Yii::getAlias('@static')?>/pc/common/js/lkt.pc.js"></script> 
<script>
var rtime = "<?=Yii::$app->params['orderExpire'] +strtotime($order->create_time) -time();?>";
var payUrl = '<?=Yii::$app->urlManager->createUrl(["order/"]);?>/';
var payStatusUrl = '<?=Yii::$app->urlManager->createUrl(["order/pay-redirect",'order_info_id'=>'']);?>';
var orderDetailUrl = '<?=Yii::$app->urlManager->createUrl(["order-details/order-detail",'order_info_id'=>'']);?>';
var orderList = '<?=Yii::$app->urlManager->createUrl(["order-details/order-list"]);?>';
var hashValue = '<?=Payment::getPaymentHash($order->order_info_id)?>';
var orderId = '<?=$order->order_info_id?>';
$(function(){
	//百度统计
	$("#payBtn").on("click", function(){
		_hmt.push(['_trackEvent', '立即支付PC', 'click', '立即支付PC']);
	});
	//返回顶部
	addGotop();
	//查看订单信息
	$(".pay-method-more-open").on("click", function(){
		var payMethodMore = $(".pay-method-more");
		payMethodMore.toggle();
		if(payMethodMore.is(":hidden")){
			$(this).children(".icon").attr("class","icon icon-arrow-down3");
		}else{
			$(this).children(".icon").attr("class","icon icon-arrow-up3");
		}
	})
	//付款倒计时43200s=12小时
	rDate("#payRtime", rtime*1);
	$("#payBtn").on("click", function(){
		var payMethod = $("[name='pay-method']:checked");
		var error = $(this).next(".error");
		if(payMethod.size()>0){
			error.text('');
			$.dialog({
				html: "请您在打开的支付平台页面进行支付，</br>支付完成前请不要关闭该窗口",
				btns: [{name:"已完成支付", ev: queryPayStatus},{name:"支付遇到问题", ev: queryPayStatus}],
				init: function(box){
					box.find(".lkt_box_close span").off().click(queryPayStatus)
				}
			});
			var id = payMethod.attr("id");
			var url = (id == 'ccbpay' || id == 'wxpay' )?payMethod.attr("id"):'alipay';
			window.open(payUrl+url+"?order_info_id="+orderId+"&hashValue="+hashValue+"&pay_method="+payMethod.val());
		}else{
			error.text("请选择一个支付方式");
		}
	});
})
function queryPayStatus(){
	$.doAjax({
		url: payStatusUrl+orderId,
		type: "post",
		success: function(data){
			if(data.flag){
				$.go(orderDetailUrl+orderId);
			}else{
				$.go(orderList);
			}
		}
	});
	return false;
}
</script>
<?php $this->endBlock();?>
